package com.example.com.transcribeeditpublish.utils;

import android.content.Context;
import android.view.View;

import com.example.com.transcribeeditpublish.TCVideoEditerWrapper;
import com.tencent.ugc.TXVideoEditConstants;
import com.tencent.ugc.TXVideoEditer;
import com.tencent.ugc.TXVideoInfoReader;

public class VideoPreareUtils {
    public static void preareEdit(Context context, String videoPath, PreareCallback preareCallback) {
        TXVideoEditer mTXVideoEditer = new TXVideoEditer(context);
        int ret = mTXVideoEditer.setVideoPath(videoPath);
        if (ret != 0) {
            preareCallback.callback(null);
            if (ret == TXVideoEditConstants.ERR_SOURCE_NO_TRACK) {
                DialogUtil.showDialog(context, "视频预处理失败", "不支持的视频格式", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                    }
                });
            } else if (ret == TXVideoEditConstants.ERR_UNSUPPORT_AUDIO_FORMAT) {
                DialogUtil.showDialog(context, "视频预处理失败", "暂不支持非单双声道的视频格式", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                    }
                });
            }
        }
        TCVideoEditerWrapper wrapper = TCVideoEditerWrapper.getInstance();
        wrapper.setEditer(mTXVideoEditer);
        final TXVideoEditConstants.TXVideoInfo info = TXVideoInfoReader.getInstance().getVideoFileInfo(videoPath);
        if (info == null) {
            DialogUtil.showDialog(context, "编辑失败", "暂不支持Android 4.3以下的系统", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                }
            });
            preareCallback.callback(null);
            return;
        }
        TCVideoEditerWrapper.getInstance().setTXVideoInfo(info);
        preareCallback.callback(info);
    }
    
    public interface PreareCallback {
        void callback(TXVideoEditConstants.TXVideoInfo info);
    }
}
